package com.e5.training.service.imp;

import java.util.List;

import org.apache.jasper.tagplugins.jstl.core.Out;

import com.e5.training.dao.UserDao;
import com.e5.training.domain.User;
import com.e5.training.service.UserService;
import com.e5.training.service.core.ServiceBase;
/**
 * 
 * @author Colin
 *
 */
public class UserServiceImp extends ServiceBase implements UserService{

	@Override
	public User login(String userid, String password) throws Exception {
		
		User user = null;
		try{
			user = userDao.isValidUser(userid,password);
		}catch(Exception ex){
			ex.printStackTrace();
			throw ex;
		}
		return user;
		//return null;
	}
	@Override
	public User getUserByUserId(String userid) throws Exception{
		User user = null;
		try{
			user = userDao.getUserByUserid(userid);
		}catch(Exception ex){
			ex.printStackTrace();
			throw ex;			
		}
		return user;
	}

	@Override
	public List<User> listAllUser() throws Exception {
        List<User> user = null;
		try
		{
        	user = userDao.listAllUser();			
		}
		catch (Exception e)
		{
		    e.printStackTrace();
		    throw e;
		}
		return user;
	}

	@Override
	public boolean signup(User user) throws Exception {
		boolean flag =false;;
		    try
			{
		    	flag = userDao.addUser(user);
			}
			catch (Exception e)
			{
				e.printStackTrace();
				throw e;
			}
		    
		return flag;
	}

	@Override
	public boolean delUser(Integer id) throws Exception {
		boolean flag = false;
		try
		{
			flag = userDao.delUser(id);	
		}
		catch (Exception e)
		{
			e.printStackTrace();
			throw e;
		}
		return flag;
	}

	@Override
	public boolean editUser(User user) throws Exception {
		boolean flag = false;
		try
		{
		    flag = userDao.editUser(user);
		}
		catch (Exception e)
		{
			e.printStackTrace();
			throw e;
		}
		return flag;
	}
	@Override
	public User getUser(String userId) {
		// TODO Auto-generated method stub
		User user = null;
		try
		{
			Integer id = Integer.parseInt(userId);
			user = userDao.getUser(id);
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		return user;
	}
	

}
